package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.combat.Report;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ReportMapper extends BaseMapper<Report> {
    //根据报告的id和用户的id查询报告
    @Select("SELECT * FROM tb_report WHERE id = #{reportId} AND user_id = #{loginUserId}")
    Report findByIdOrUid(@Param("reportId") Integer reportId, @Param("loginUserId") Long loginUserId);

    //插入报告
    @Insert("insert into tb_report (id, user_id,questionnaire_id,conclusion,cover,score) values (null, #{userId}, #{questionnaireId}, #{conclusion}, #{cover}, #{score})")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    void insertReport(Report report);


    //根据用户的ID查询报告
    @Select("SELECT * FROM tb_report WHERE user_id =#{id}")
    List<Report> findByUserId(@Param("id") Integer id);
    //删除报告
    @Delete("DELETE  FROM tb_report WHERE id =#{byUserIdReportId}")
    void deleteReport(Integer byUserIdReportId);

    //根据用户的id和试卷的Id查询报告
    @Select("SELECT *  FROM tb_report WHERE user_id =#{loginUserId} AND questionnaire_id = #{id}")
    Report findByUserIdOrQuestionnaireId(@Param("loginUserId") Long loginUserId, @Param("id") Integer id);
    //根据性格和问卷的ID查找性格
    @Select("SELECT * FROM tb_report WHERE conclusion = #{conclusion} AND questionnaire_id = #{questionnaireId}")
    List<Report> findByConclusionOrQuestionnaireId(@Param("conclusion") String conclusion, @Param("questionnaireId") Integer questionnaireId);
}
